package servlets;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import beans.UserDAO;


//本程序是为了客户端用ajax检测用户号和密码是否正确

@WebServlet("/CheckyanzhengmaServlet")
public class CheckyanzhengmaServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public CheckyanzhengmaServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		//response.getWriter().append("Served at: ").append(request.getContextPath());
		
		String yanzhengma=request.getParameter("yanzhengma");//接到的验证码
		String savedyanzhengma=(String)request.getSession().getAttribute("checkpicCode");//已经产生的验证码
		boolean flag=yanzhengma.equals(savedyanzhengma);

		response.setCharacterEncoding("UTF-8");//由于返回了指定的页面，所以不需要设置content-type了
		if(flag) {
			response.getWriter().append("success");
			
		}else {
			response.getWriter().append("号或密码不正确");
		}
		

	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
